home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 2003 September / PC Answers September 2003.iso / Software / trial / MonitorIT 5.2.06 / monitorit_fullsetup.exe / data1.cab / Js / ServerWatchFunc.js < prev    next >
Encoding:
JavaScript  |  2003-06-24  |  14.3 KB  |  376 lines

  1. /* ======================================================================
  2. DESC: Common Functions for the View Servers Operations
  3.  
  4. PLATFORMS: >= MS IE 4.0
  5.  
  6. USAGE NOTES: 
  7. ====================================================================== */
  8. var ALupMode = ""; // Lookup Mode of Operation, Computer, Counter
  9. var ServicesArray = new Array("PING","HTTP","FTP","SMTP","POP","DNS","USER","SQL","SNMP","TELNET","ORACLE","L_NOTES","AGENT");
  10. var ServicesRecCount = 0; // Count of records returned from Services Lookup operation
  11. var AlertLupRecCount = 0; // Count of records returned from Alert Lookup operation
  12. var AlertSelectIdx = 0; // Index of currently selected Alert 
  13.  
  14. /* Initial Alert Lookup Request */
  15. var AlLookupBsy = false;
  16. function processAlLookup() {
  17.     if ( AlLookupBsy ) // exit if already Busy
  18.         return;
  19.     if ( AL_AlertStoreArr.length > 0 ) 
  20.         return; // exit if already exists
  21.     AlLookupBsy = true; // set Busy    
  22.     
  23.     AlertLupRecCount = 0; // clear Lookup record counter
  24.     if ( RpmCC_VA.AlertGroupLookup("*") ) {
  25.             ALupMode = "";
  26.             AlLookupBsy = false; // free    
  27.             top.Rstatus.Pstat("Unable to start the Alert LOOKUP request",true);
  28.     }
  29.     else {
  30.             ALupMode = "Lookup"; // set Mode of operation
  31.             top.Rstatus.Pstat("One moment while Alert LOOKUP request completes");
  32.     }
  33. }
  34.  
  35. /* Process Alert LOOKUP RECORD Event */
  36. var    AlertRecLength = 3; // Alert Lookup record length
  37. function AlertLupRec(AlID, AlName, AlDesc) {
  38.     var i = AlertLupRecCount * AlertRecLength;
  39.     AL_AlertStoreArr[i++] = AlName; //+0
  40.     AL_AlertStoreArr[i++] = AlID;
  41.     AL_AlertStoreArr[i] = AlDesc;
  42.     ++AlertLupRecCount; // bump record received counter
  43. }
  44.  
  45. /* Process DB Error in Alert Lookup Operation */
  46. function processAlertOpError() {
  47.     AlLookupBsy = false; // free    
  48.     top.Rstatus.Pstat("An error occurred during Alert LOOKUP operation",true);
  49. }
  50. function processComputerOpError() {
  51.     AlLookupBsy = false; // free    
  52.     top.Rstatus.Pstat("An error occurred during Computer LOOKUP operation",true);
  53. }
  54. /* Process Alert/Object OP Complete Event */
  55. function processAlertOpComplete() {
  56.     top.Rstatus.Pstat("Request Completed");
  57.     if (ALupMode == "Lookup") {
  58.         // Do Services Lookup
  59.         ServicesRecCount = 0; // reset count
  60.         ALupMode = "ServicesLookup";
  61.         rstat = RpmCC_VA.ServicesLookup("","","ComputerID,ID DESC");    
  62.         if ( rstat ) { // if unable to initiate request        
  63.             AlLookupBsy = false; // free    
  64.             top.Rstatus.Pstat("Unable to start the Services LOOKUP request",true);
  65.         }
  66.         else { // waiting for OperationCompleteEvent
  67.             top.Rstatus.Pstat("One moment while Services LOOKUP request completes");
  68.         }
  69.     }
  70. }
  71.  
  72. // Process Serverices LOOKUP Record Event
  73. var ServicesRecLength = 4; // Services Lookup record length
  74. function processServicesRecord(SRVstrg) {
  75.     var warr = new Array();
  76.     warr = SRVstrg.split("~");
  77.     var j = ServicesRecCount * ServicesRecLength;
  78.      AC_ServicesStoreArr[j] = warr[1]; // Computer ID
  79.       AC_ServicesStoreArr[j+1] = warr[2]; // AlertGroup ID
  80.       warr[3] = (warr[3] == "SQLCONNECT") ? "SQL" : warr[3];
  81.       AC_ServicesStoreArr[j+2] = warr[3]; // Type
  82.       AC_ServicesStoreArr[j+3] = warr[11]; // Disable Flag
  83.     ++ServicesRecCount; // bump record counter
  84. }
  85.  
  86. /* Process DB Error in Services Lookup Operation */
  87. function processServicesOpError() {
  88.     AlLookupBsy = false; // free    
  89.     top.Rstatus.Pstat("An error occurred during Computer LOOKUP operation",true);
  90. }
  91. // Prcoess Services Operation Complete Event
  92. function processServicesOpComplete() {
  93.     if (ALupMode == "ServicesLookup"){
  94.         top.Rstatus.Pstat("Done");
  95.         ALupMode = "";
  96.         getComputerInfo(); // go start lookupfor Computer info
  97.         processServiceTree(); // create Services tree
  98.         AlLookupBsy = false; // free    
  99.         // If Filter should be validated,do it
  100.         if ( ValidateFilter ) {
  101.            ValidateFilter = false; // reset
  102.            for ( var i=0,j=0; i<AC_FilterStoreArr.length; i+=FilterRecLength ) {
  103.                VCid = AC_FilterStoreArr[i]; // Computer ID
  104.                VStyp = AC_FilterStoreArr[i+1]; // Service Type
  105.                if ( !IsActiveServiceWatch(VCid,VStyp) ) { // if not 
  106.                     for (var j=i+FilterRecLength; j < AC_FilterStoreArr.length; ++i, ++j) {
  107.                         AC_FilterStoreArr[i] = AC_FilterStoreArr[j];
  108.                     }
  109.                     AC_FilterStoreArr.length -= FilterRecLength;
  110.                     i -= FilterRecLength; // adjust index to compensate for deleted entry
  111.                 }
  112.             }
  113.             // Update Filter save
  114.             RpmCC_VA.RegSetKey(top.banner.ServerID+"ServerWatchFilterArray",AC_FilterStoreArr.join("~"));
  115.         }
  116.     }
  117. }
  118. // See if Specified Parameters are a Valid ServiceWatch
  119. function IsActiveServiceWatch(ACid,AStyp) {
  120.      for ( var i=0,j=0;i<AC_ServicesStoreArr.length; i+=ServicesRecLength ) {
  121.           // Match on Type and Computer ID Assigned to an Alert Group
  122.           if ( AC_ServicesStoreArr[i+2] == AStyp && AC_ServicesStoreArr[i] == ACid ) {
  123.               if ( AC_ServicesStoreArr[i+1] != 0 ) // if assigned an Alert
  124.                   return true;
  125.               else
  126.                   return false;
  127.           }
  128.     }
  129. }
  130.  
  131. // Process and Display the Services:Computer Tree
  132. var ServExpandedCount = 0;
  133. function processServiceTree() {
  134.     AL_CCOneServ.innerHTML = ""; // clear display
  135.     /* Format and Output Service tree list */
  136.     setOutHeader("Service : Server/Computer Tree"); // define output table header    
  137.     ServExpandedCount = 0; // init
  138.     for ( var i=0; i<ServicesArray.length; i++) {
  139.         CCEs += "<table border='0' cellpadding='0' cellSpacing='0' width='450'><tr><td width='25'> </td>";
  140.         Iprefx = ( i+1 >= ServicesArray.length ) ? "L" : "T";
  141.           CCEs += "<td width='19' align='center'><img id='sima" + i + "' expanded='0' src='images/" + Iprefx + "plus.gif' style='cursor:hand' onclick='procSrvImgClick(this)' width='19' height='20'></td>";
  142.         CCEs += "<td width='19' align='center'><img id='simb" + i + "' src='images/sAdminServers.gif' style='cursor:hand' onclick='procSrvImgClick(this)' width='16' height='16' title='";
  143.         CCEs += "'></td><td width='*' class='optext'>" + ServicesArray[i] + "</td></tr></table>";
  144.         CCEs += "<div id='sexp" + i + "' compcount='0'></div>";
  145.       }
  146.     AL_CCOneServ.insertAdjacentHTML("beforeEnd",CCEs);
  147. }
  148. /* Display Header for Service and Object:Counter Trees */
  149. function setOutHeader(Tstrg) {
  150.     CCEs = "<table border='0' cellpadding='0' cellSpacing='0' width='450'>";
  151.     CCEs += "<tr><td width='25'> </td>";
  152.       CCEs += "<td width='19' height='20' align='center'><img src='images/topopen.gif' width='19' height='20'></td><td colspan='2' width='*' class='optextn'>" + Tstrg + "</td></tr></table>";
  153. }
  154.  
  155. /* Process Click on Service in Service Tree */
  156. var CurExpServIx = null; // Index to Current Expanded Service
  157. var EObj = null; // expanded Service Object
  158. var CTparm = "optext";
  159. var warrsic = new Array();
  160. function procSrvImgClick(SIm) {
  161.     isx = SIm.id;  
  162.     if ( isx.charAt(0) != "s" || ALupMode != "" ) { // if not a "simaxx"
  163.         top.banner.beep();
  164.         return;
  165.     }
  166.     var cx = isx.substring(4,isx.length); // Strip off index
  167.  
  168.     CurExpServIx = parseInt(cx,10);
  169.     CObj = document.all["sima"+cx];
  170.     EObj = document.all["sexp"+cx];
  171.     Cpfx = (CurExpServIx+1 >= ServicesArray.length) ? "L" : "T";
  172.  
  173.     if ( CObj.expanded == "1" ) { // if currently expanded
  174.         CObj.src = "images/" + Cpfx + "plus.gif";
  175.         EObj.style.display = "none";
  176.         EObj.innerHTML = ""; // Contract 
  177.        CObj.expanded = "0"; // Set contracted
  178.        ServExpandedCount-=EObj.compcount; // decrement count of open computers
  179.      }
  180.     else { // otherwise Expand
  181.         CObj.src = "images/" + Cpfx + "minus.gif";
  182.           CObj.expanded = "1"; // Set expanded
  183.           
  184.           // find and list computers for expanded service
  185.         CCEs = "";
  186.         CurCmpIx = 0;
  187.         var cName = ""; // Computer Name
  188.        var SType = ServicesArray[CurExpServIx]; // Service Type
  189.        for ( var i=0,j=0; i<AC_ServicesStoreArr.length; i+=ServicesRecLength ) {
  190.            // Match on Type and Assigned to an Alert Group
  191.            if ( AC_ServicesStoreArr[i+2] == SType && AC_ServicesStoreArr[i+1] != "0") {
  192.                 CTparm = ( AC_ServicesStoreArr[i+3] == "1" ) ? "optextr" : "optext";
  193.                 warrsic[j] = AC_ServicesStoreArr[i];
  194.                   ++j; // bump computer count
  195.            }
  196.         }
  197.  
  198.         ALupMode = ""; // reset mode
  199.           ServExpandedCount+=j; // increment total number of computers opened
  200.         EObj.compcount = j; // set number computers opened
  201.         if ( (CmpsExpected = j) == 0 ) {
  202.             top.Rstatus.Pstat("No Computers defined for "+ SType +" Service");
  203.         }
  204.         else {
  205.             top.banner.processStartComm(); 
  206.             top.Rstatus.Pstat("Moment Please");
  207.             ETid = setTimeout("processEditSrvComputerContinue()",100); // Delay 
  208.         }
  209.     }
  210.     // enable SelectAll/UnselectAll buttons if computers opened
  211.     if ( ServExpandedCount > 0 ) { 
  212.        SetButtonState(bSelC,"0");
  213.        SetButtonState(bUselC,"0");
  214.    }
  215.    else { // otherwise disable the buttons
  216.        SetButtonState(bSelC,"1");
  217.        SetButtonState(bUselC,"1");
  218.    }
  219. }
  220. function processEditSrvComputerContinue() {
  221.     ETid = null;
  222.     for ( var i=0; i<CmpsExpected; i++ ) {
  223.         cName = getCompNameDesc(warrsic[i]); // get Computer Name & Desc
  224.          processEditSrvComputer(cName,curCompDesc,warrsic[i]);
  225.      }        
  226.     processEditSrvComputerComplete();
  227. }
  228.  
  229. function SetButtonState(BtObj,BState) {
  230.     //BtObj.className = (BState == "0") ? "BoxButton" : "BoxButtonD";
  231.     BtObj.disabled = (BState == "0") ? "" : "disabled";
  232. }
  233. function processEditSrvComputer(CmpNme,CmpDesc,CID) {
  234.     Opfx = (CurExpServIx+1 >= ServicesArray.length) ? "White" : "I";
  235.     Mpfx = (CurCmpIx+1 == CmpsExpected) ? "L" : "T";
  236.     
  237.     CCEs += "<table border='0' cellpadding='0' cellSpacing='0' width='450'>";
  238.     CCEs += "<tr><td width='25'> </td><td width='19' height='20' align='center'><img src='images/" + Opfx + ".gif' width='19' height='20'></td>";
  239.     CCEs += "<td width='19' height='20' align='center'><img src='images/" + Mpfx + ".gif' width='19' height='20'></td>";
  240.       CCEs += "<td width='11' align='center' style='backgroundColor:white'><img id='vima" + CurExpServIx + "_" + CurCmpIx;
  241.  
  242.     if ( CheckFilterStore(CID,ServicesArray[CurExpServIx]) && AC_FilterStoreArr.length != 0 ) {
  243.        CCEs += "' checked='1' src='images/Checked.gif'"; 
  244.        CmpImg = "sMicroscope.gif";
  245.     }
  246.     else {
  247.        CCEs += "' checked='0' src='images/Unchecked.gif'";
  248.        CmpImg = "Computer.gif";
  249.     }
  250.     var gn = getCurrentAlertGrpName(CID,ServicesArray[CurExpServIx]);
  251.     if ( CTparm == "optextr" ) { // if suspended
  252.         gn += " : SUSPENDED";
  253.     }
  254.       CCEs += " compid='" +CID+"' style='cursor:hand' onclick='procCmpImgClick(this)' width='9' height='9'></td>";
  255.     CCEs += "<td width='19' align='center'><img id='pimb" + CurExpServIx + "_" + CurCmpIx + "' src='images/"+CmpImg+"' style='cursor:hand' onclick='procCmpImgClick(this)' width='15' height='16' title='Desc: ";
  256.     CCEs += CmpDesc;
  257.     if ( CmpDesc.length > 0 )
  258.         CCEs += " ; ";
  259.     CCEs += "Watch/Alert: "+gn+"'></td>";
  260.     CCEs += "<td width='*' class='"+CTparm+"'>" + CmpNme + "</td>";
  261.     CCEs += "</tr></table>";
  262.     ++CurCmpIx; // bump index
  263. }
  264.  
  265. function getCurrentAlertGrpName(CmpID,CSType) {
  266.       for ( var i=0,j=0; i<AC_ServicesStoreArr.length; i+=ServicesRecLength ) {
  267.        // Match on Type and Assigned to an Alert Group
  268.        if ( AC_ServicesStoreArr[i+2] == CSType && AC_ServicesStoreArr[i] == CmpID ) {
  269.            var gn = getOnlyAlertName(AC_ServicesStoreArr[i+1]); // get name based on Alert Group ID    
  270.            return gn;    
  271.        }
  272.    }
  273.    return "";
  274. }
  275.  
  276. /* Read of Computers complete; Output formatted Computers */
  277. function processEditSrvComputerComplete() {
  278.     EObj = document.all["sexp"+CurExpServIx];
  279.     EObj.insertAdjacentHTML("beforeEnd",CCEs);
  280.     EObj.style.display = "";
  281.     EObj.compcount = CurCmpIx; // Count of Computers
  282.     document.all["sima"+CurExpServIx].scrollIntoView(true);
  283.     ALupMode = "";
  284.     top.Rstatus.Pstat("Request Completed");
  285.     top.banner.processStopCommX();
  286. }
  287.  
  288. /* Process Click to Check or Uncheck a Computer */
  289. function procCmpImgClick(CmpIm) {
  290.     isx = CmpIm.id;  
  291.     if ( isx.charAt(0) != "v") // if not a  or "vimaxx_yy"
  292.                 return;
  293.     var cx = isx.substring(4,isx.length); // Strip off index
  294.     lx = cx.lastIndexOf("_"); // derive suffix to the Service DIV ID
  295.     var dx = cx.substring(0,lx);
  296.  
  297.     var CObj = document.all["vima"+cx]; // Clicked Computer Entry
  298.     var FObj = document.all["pimb"+cx]; 
  299.     if ( CObj.checked == "1" ) { // if currently Checked, Uncheck
  300.         FObj.src = "images/Computer.gif";
  301.         CObj.src = "images/Unchecked.gif";
  302.        CObj.checked = "0"; // Set Unchecked
  303.        RemoveFromFilterStore(CObj.compid,ServicesArray[dx]);
  304.    }
  305.     else { // otherwise Check
  306.         FObj.src = "images/sMicroscope.gif";
  307.         CObj.src = "images/Checked.gif";
  308.        CObj.checked = "1"; // Set Checked
  309.        AddToFilterStore(CObj.compid,ServicesArray[dx]);
  310.     }
  311.     SpecificationsMade = true; // flag that a change has been made
  312. }
  313.  
  314. // Process SelectALL or UnselectALL
  315. function processSelect(Pflg) {
  316.     var CObj = null;
  317.     // Check each Service item to see if expanded
  318.     for ( var i=0; i<ServicesArray.length; i++ ) {
  319.         if ( document.all["sima"+i].expanded == "1" ) {
  320.             // if expanded 
  321.             CCnt = document.all["sexp"+i].compcount;  // computer count
  322.             for ( var j=0; j<CCnt; j++ ) {
  323.                 CObj = document.all["vima"+i+"_"+j]; // computer entry in tree
  324.                 CObj.checked = Pflg; // set for select/unselect
  325.                 procCmpImgClick(CObj); // go process
  326.             }
  327.         }
  328.     }
  329. }
  330.  
  331. /* Get only the Alert Name from Store based on Alert ID */
  332. function getOnlyAlertName(AgID) {
  333.     var AlertName = "";
  334.     for (i=0; i < AL_AlertStoreArr.length; i+=AlertRecLength) {
  335.         if ( AL_AlertStoreArr[i+1] == AgID ) {
  336.             AlertName = AL_AlertStoreArr[i];
  337.             break;
  338.         }
  339.     }
  340.     return AlertName;
  341. }
  342. // Read all Computers assigned to Alert Groups
  343. function getComputerInfo() {
  344.     var GCIDArr = new Array();
  345.     var prevCID = "";
  346.    AC_CompStoreArr.length = 0; // clear computer store 
  347.       for ( var i=0,j=0; i<AC_ServicesStoreArr.length; i+=ServicesRecLength ) {
  348.           // Match on Assigned to an Alert Group
  349.           if ( AC_ServicesStoreArr[i+1] != "0" && AC_ServicesStoreArr[i] != prevCID ) {
  350.               if ( GCIDArr != "" ) { 
  351.                   GCIDArr += ","; 
  352.               } 
  353.               GCIDArr += AC_ServicesStoreArr[i]; // Add Computer ID
  354.               prevCID = AC_ServicesStoreArr[i];              
  355.               ++j; // bump computer count
  356.           }
  357.     }
  358.     ALupMode = ""; // reset mode
  359.     if ( j > 0 ) { // if some computers assigned
  360.         /* Lookup Computer Names and Descriptions */
  361.         if ( RpmCC_VA.ComputerLookupByIDArray(GCIDArr) ) {
  362.             top.Rstatus.Pstat("Unable to start the Computer LOOKUP request",true);
  363.         }
  364.         else {
  365.             ALupMode = "InitComputerLookup"; // set Mode of operation
  366.             top.Rstatus.Pstat("One moment while Computer LOOKUP request completes");
  367.         }
  368.     }
  369.     else {
  370.         WarningBox.style.display = "none";
  371.         WarningBox1.style.display = "";
  372.         top.Rstatus.Pstat("No status messages available",true);
  373.         top.banner.processStopCommX(); 
  374.     }
  375. }
  376.